<template>
  <div class="release">
    <div class="top">
      <van-nav-bar title="我的发布" left-arrow @click-left="$router.back()" />
    </div>

    <commonList :API="getUserList" :params="{ uid }" :refresh="true">
      <template #default="{ list }">
        <div class="main" v-for="item in list" :key="item._id">
          <van-swipe-cell>
            <van-card :desc="item.time | conversion" :title="item.title">
              <template #tags>
                <van-tag style="margin-right: 10px" plain type="danger"
                  >类型</van-tag
                >
                <span>{{ item.cate_name }}</span>
              </template>
              <template #thumb>
                <van-image
                  width="100"
                  height="100"
                  lazy-load
                  v-for="img in item.imageSrc"
                  :key="img._id"
                  :src="img"
                />
              </template>

              <template #num>
                <van-icon name="good-job" color="red" size="18" />
                <span>{{ item.like }}</span>
              </template>
            </van-card>

            <template #right>
              <van-button
                square
                text="删除"
                type="danger"
                class="delete-button"
                @click="delUserAarticle(item._id)"
              />
            </template>
          </van-swipe-cell>
        </div>
      </template>
    </commonList>
  </div>
</template>

<script>
import { getUserList, getDelList } from "@/api/api";
import { mapState } from "vuex";
import { Card, Tag, Lazyload, SwipeCell, } from "vant";
import commonList from "@/components/commonList.vue";
export default {
  data() {
    return {
      getUserList,
    };
  },
  components: {
    [Card.name]: Card,
    [Tag.name]: Tag,
    [commonList.name]: commonList,
    [Lazyload.name]: Lazyload,
    [SwipeCell.name]: SwipeCell,
  },
  computed: {
    ...mapState(["uid"]),
  },
  created() {},
  methods: {
    // 点击删除
    delUserAarticle(_id) {
        let {uid}=this
      console.log(_id);
      getDelList({
        _id,
        uid
      }).then(res=>{
        console.log(res);
       if (res.code==0) {
         this.$toast(res.msg)
       this.$Bus.$emit('dete',_id)
        // this.getList()
       }else{
        this.$toast(res.msg)
       }
      })
    },
  },
  filters: {
    //3.定义一个处理函数，参数value为要处理数据
    conversion: function (value) {
      //调用Date的方法，处理时间戳
      return new Date(value).toLocaleString();
    },
  },
};
</script>

<style lang="scss" lang="less" scoped>
.release {
  background-color: rgb(245, 247, 249);
  height: 100vh;
}
::v-deep .van-card__content {
  margin-left: 10px;
}
::v-deep .van-swipe-cell__right {
  right: -1px;
}

.goods-card {
  margin: 0;
  background-color: #fff;
}

.delete-button {
  height: 100%;
}
</style>